/**
 * 处理发送请求的Action::GET
 * 尝试捕捞drifting状态的瓶子到系统中
 * Author: frogcherry
 * Email: frogcherry@gmail.com
 * created: 2011.12.08
 */

var mongoDao = require("../MongoDao.js");
var pieCenter = require("../cache/PieCenter.js");

var SalvageAction = exports;

SalvageAction.handle = function(urlObj){

	return function (req, res) {
		var uid = urlObj.query.uid;
		if (uid) {
//			console.log("app_uid:" + uid);
			mongoDao.db.drifting_msg.findOne({
				"landed" : 0,
				"senderId" : {"$ne" : uid}
			}, function(err,data){
					if (err) {
						console.error("Error when find drifting msg.");
						console.error(err);
						res.simpleJSON(200, {"type" : "error", "error": "210" });//数据库错误
					} else {
						res.simpleJSON(200, {"type" : "ok", "msg": data });
					}
			});
		} else {
			res.simpleJSON(200, {"type" : "error", "error": "204" });//请求错误
		}
	  };
};

